/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn;

import java.util.Random;
import java.util.Scanner;

/**
 * <p>Project: app2022 - Reg3
 * <p>Powered by webrx On 2022-01-13 11:32:42
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Reg3 {
    public static void test(String[] args) {
        //3. 判断字符串有没有数字 \d 代表 [0-9]
        //\d{3} [0-9]{3} \D 代表 [^0-9] 非数字
        String s = "sqlserver"; //1l
        System.out.println(s.matches(".*\\d.*"));

        //4.判断手机号是不是格式正确
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入手机号：");
        String phone = sc.nextLine();
        String pattern = "1[3,5,8]\\d{9}";
        if(phone.trim().matches(pattern)){
            System.out.printf("%s，手机号正确",phone);
        }else{
            System.err.printf("%s，是错误的手机号",phone);
        }
    }


    public static void main(String[] args) {
        System.out.println(check());
        System.out.println(check(6));
    }

    public static String check(){
        return check(4);
    }

    public static String check(int len){
        Random rand = new Random();
        StringBuilder sbu = new StringBuilder();
        for (int i = 0; i < len; i++) {
            int t = rand.nextInt(0,10);
            sbu.append(String.format("%d",t));
        }
        return sbu.toString();
    }
}
